package com.itboy.mall.pms.spuinfodesc.controller;

import java.util.List;
import java.util.Arrays;

import lombok.RequiredArgsConstructor;
import javax.validation.constraints.*;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.itboy.common.annotation.RepeatSubmit;
import com.itboy.common.annotation.Log;
import com.itboy.common.core.controller.BaseController;
import com.itboy.common.core.domain.AjaxResult;
import com.itboy.common.enums.BusinessType;
import com.itboy.mall.pms.spuinfodesc.vo.MallSpuInfoDescVo;
import com.itboy.mall.pms.spuinfodesc.bo.MallSpuInfoDescQueryBo;
import com.itboy.mall.pms.spuinfodesc.bo.MallSpuInfoDescAddBo;
import com.itboy.mall.pms.spuinfodesc.bo.MallSpuInfoDescEditBo;
import com.itboy.mall.pms.spuinfodesc.service.IMallSpuInfoDescService;
import com.itboy.common.utils.poi.ExcelUtil;
import com.itboy.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * spu信息介绍Controller
 *
 * @author itboy
 * @date 2021-08-08
 */
@Validated
@Api(value = "spu信息介绍控制器", tags = {"spu信息介绍管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/mall/spuInfoDesc")
public class MallSpuInfoDescController extends BaseController {

    private final IMallSpuInfoDescService iMallSpuInfoDescService;

    /**
     * 查询spu信息介绍列表
     */
    @ApiOperation("查询spu信息介绍列表")
    @PreAuthorize("@ss.hasPermi('mall:spuInfoDesc:list')")
    @GetMapping("/list")
    public TableDataInfo<MallSpuInfoDescVo> list(@Validated MallSpuInfoDescQueryBo bo) {
        return iMallSpuInfoDescService.queryPageList(bo);
    }

    /**
     * 导出spu信息介绍列表
     */
    @ApiOperation("导出spu信息介绍列表")
    @PreAuthorize("@ss.hasPermi('mall:spuInfoDesc:export')")
    @Log(title = "spu信息介绍", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult<MallSpuInfoDescVo> export(@Validated MallSpuInfoDescQueryBo bo) {
        List<MallSpuInfoDescVo> list = iMallSpuInfoDescService.queryList(bo);
        ExcelUtil<MallSpuInfoDescVo> util = new ExcelUtil<MallSpuInfoDescVo>(MallSpuInfoDescVo.class);
        return util.exportExcel(list, "spu信息介绍");
    }

    /**
     * 获取spu信息介绍详细信息
     */
    @ApiOperation("获取spu信息介绍详细信息")
    @PreAuthorize("@ss.hasPermi('mall:spuInfoDesc:query')")
    @GetMapping("/{spuId}")
    public AjaxResult<MallSpuInfoDescVo> getInfo(@NotNull(message = "主键不能为空")
                                                  @PathVariable("spuId") Long spuId) {
        return AjaxResult.success(iMallSpuInfoDescService.queryById(spuId));
    }

    /**
     * 新增spu信息介绍
     */
    @ApiOperation("新增spu信息介绍")
    @PreAuthorize("@ss.hasPermi('mall:spuInfoDesc:add')")
    @Log(title = "spu信息介绍", businessType = BusinessType.INSERT)
    @RepeatSubmit
    @PostMapping()
    public AjaxResult<Void> add(@Validated @RequestBody MallSpuInfoDescAddBo bo) {
        return toAjax(iMallSpuInfoDescService.insertByAddBo(bo) ? 1 : 0);
    }

    /**
     * 修改spu信息介绍
     */
    @ApiOperation("修改spu信息介绍")
    @PreAuthorize("@ss.hasPermi('mall:spuInfoDesc:edit')")
    @Log(title = "spu信息介绍", businessType = BusinessType.UPDATE)
    @RepeatSubmit
    @PutMapping()
    public AjaxResult<Void> edit(@Validated @RequestBody MallSpuInfoDescEditBo bo) {
        return toAjax(iMallSpuInfoDescService.updateByEditBo(bo) ? 1 : 0);
    }

    /**
     * 删除spu信息介绍
     */
    @ApiOperation("删除spu信息介绍")
    @PreAuthorize("@ss.hasPermi('mall:spuInfoDesc:remove')")
    @Log(title = "spu信息介绍" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{spuIds}")
    public AjaxResult<Void> remove(@NotEmpty(message = "主键不能为空")
                                       @PathVariable Long[] spuIds) {
        return toAjax(iMallSpuInfoDescService.deleteWithValidByIds(Arrays.asList(spuIds), true) ? 1 : 0);
    }
}
